/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.tmd.controlefinanceiro.bean;

import br.com.tmd.controlefinanceiro.modelo.Conta;
import br.com.tmd.controlefinanceiro.persistence.ContaDao;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author luis
 */
@ManagedBean(name = "contaBean")
@RequestScoped
public class ContaBean {
    
    private Conta conta = new Conta();
    private List<Conta> listaContas;
    
    private Integer contaId;
    
    public ContaBean() { 
    }
    
    public Integer getContaId() {
        return contaId;
    }

    public void setContaId(Integer contaId) {
        this.contaId = contaId;
    }    

    public Conta getConta() {
        return conta;
    }

    public void setConta(Conta conta) {
        this.conta = conta;
    }

    public List<Conta> getListaContas() throws Exception {
        ContaDao dao = new ContaDao();
        listaContas = dao.listaContas();
        return listaContas;        
    }

    public void setListaContas(List<Conta> listaContas) {
        this.listaContas = listaContas;
    }
    
    public String novo() {
        this.conta = new Conta();
        return "contas?faces-redirect=true";
    }
     
     public String novo1() {
        return "transferencias?faces-redirect=true";}
    
    
    public String salvar(){
        
        FacesContext context = FacesContext.getCurrentInstance();
        ContaDao dao = new ContaDao();
        dao.salvar(conta);
        
        FacesMessage facesMessage = new FacesMessage("Conta criada com sucesso");
        context.addMessage(null, facesMessage);
        this.conta = new Conta();
        
        //return "contas?faces-redirect=true";
        return null;
    }
    
    public String formPrincipal() {
        return "principal?faces-redirect=true";
    }
    
    public String consultaContas() {
        return "consultaContas?faces-redirect=true";
    }
      
    
}
